<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

//哈希加密
use Hash;
//数据库
use DB;
//数据验证
use App\Http\Requests\HomePasswordeditPostRequest;
// use App\Http\Requests\password_editControllerRequest;

use App\Http\Requests;
use App\Http\Controllers\Controller;


class PasswordeditController extends Controller
{
	
	/*
		显示密码修改
	*/
	public function passwordedit()
	{
		if(session('id')){
			$menu = HomeListController::menu(0);
			//解析模板
			return view('home.person.passwordedit',['menu'=>$menu]);
		}else{
			// return back()->with('error','您还没有登录');
			$menu = HomeListController::menu(0);
			return view('home.login.login',['menu'=>$menu]);
			// return view('home.person.password');

		}
		//解析模板
		// return view('home.person.passwordedit');
	}
	public function xiugai(HomePasswordeditPostRequest $request)
	{
		$user = DB::table('user')->where('id',session('id'))->first();
      //检测密码是否一致
		$data = [];
       if(!Hash::check($request->input('password'),$user->password)){
       		return back()->with('error','请输入正确密码');
       }else{
       		if($request->input('newpassword') == $request->input('password')){
       			return back()->with('error','原密码不能与新密码相同');
       		}else{
       			$data['password'] = Hash::make($request->input('newpassword'));
   				$res = DB::table('user')
	            	->where('id',session('id'))
	            	->update($data);
	            return redirect('/login')->with('success','密码修改成功');

       		}
       	}
       		

    }  		
	

	
}  
